package hu;

import java.util.*;

public class packet {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(m <= n){
            System.out.println(n - m);
            return;
        }
        int[] dp = new int[m + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        for (int i = 1; i <= n; i++) {
            dp[i] = n - i;
        }
        for (int i = n + 1; i <= m; i++) {
                if(i % 2 == 0){
                    dp[i] = Math.min(dp[i - 1] + 1, dp[i / 2] + 1);
                }
                else dp[i] = Math.min(dp[i - 1] + 1, dp[(i + 1) / 2] + 2);
        }
        System.out.println(dp[m]);
    }
}
